<template>
    <div class="app-container dialog">
        <div class="title">网络故障</div>
        <div class="Subhead">基本信息</div>
        <el-form
            :model="form"
            :rules="rules"
            ref="ruleForm"
            label-width="100px"
            class="demo-ruleForm"
        >
            <el-form-item label="标题" prop="title">
                <el-input readonly style="width: 760px" v-model="form.title"></el-input>
            </el-form-item>
            <el-row>
                <el-col :span="6">
                    <el-form-item label="联系人员" prop="contact_person">
                        <el-input readonly v-model="form.contact_person"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="联系方式" prop="contact_information">
                        <el-input readonly v-model="form.contact_information"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <div class="Subhead">故障信息</div>
            <el-row>
                <el-col :span="6">
                    <el-form-item label="网络环境" prop="network_environment">
                        <el-select disabled clearable filterable v-model="form.network_environment">
                            <el-option v-for="item in networkList" :key="item.id" :label="item.name" :value="item.id">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="IP地址" prop="ipLocation">
                        <el-input readonly v-model="form.ipLocation"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-form-item label="故障现象">
                <editor
                :readonly="true"
                    v-model="form.fault_phenomenon"
                    style="
                        min-height: 192px;
                        max-height: 400px;
                        overflow-y: auto;
                       
                    "
                    :min-height="192"
                    :max-height="400"
                />
            </el-form-item>
        </el-form>
        <div class="Subhead">附件
            <el-upload
                style="display: inline-block;"
                class="upload-demo"
                accept
                v-if="false"
                list-type="picture"
                :show-file-list="false"
                ref="upload"
                :file-list="fileList"
                action=""
                :on-remove="handleChange"
                :on-change="handleChange"
                :auto-upload="false"
            >
            <img style="width: 20px;cursor: pointer;vertical-align: middle;"
                 src="../../../assets/icons/add.png"
                alt="">
            </el-upload>
        </div>
        <el-table
            :data="fileList"
        >
            <el-table-column label="文件名称">
                <template slot-scope="scope">
                    {{
                        scope.row.fileName
                    }}
                </template>
            </el-table-column>
            <el-table-column label="文件类型">
                <template slot-scope="scope">
                    {{
                        scope.row.fileExt
                    }}
                </template>
            </el-table-column>
            <el-table-column
                label="操作"
                width="100"
                class-name="small-padding fixed-width"
            >
                <template slot-scope="scope">
                   <el-button
                       size="mini"
                       type="text"
                       icon="el-icon-view"
                       v-show="scope.row.fileExt == 'jpeg' ||
                                   scope.row.fileExt == 'jpg' ||
                                   scope.row.fileExt == 'png' ||
                                   scope.row.fileExt == 'pdf' ||
                                   scope.row.fileExt == 'gif'"
                       @click="previewFile(scope.row)"
                       >预览
                   </el-button>

                   <el-button
                       size="mini"
                       type="text"
                       icon="el-icon-download"
                       v-if="scope.row.id"
                       @click="download(scope.row)"
                       >下载
                   </el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-dialog :visible.sync="dialogVisible">
            <div style="max-height: 90vh; overflow-y: scroll">
                <img width="100%" :src="dialogImageUrl" alt="" />
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { treeselect } from "@/api/system/dept";
import Editor from "@/components/Editor";
import { cloudUpList } from "@/api/cloud/cloud";
import { definition } from "@/api/WorkOrder/OperationMaintenance.js"
import { uploadFile } from "@/api/system/upload.js";
import { Getformdata,taskComplete } from "@/api/todoItem/todo.js";
import {
    DelectUploadFile
  } from "@/api/cloud/cloud";
export default {
    name: "NetworkFailuresDonedetails",
    components: {
        Editor,
    },
    data(){
        return{
          base_url: process.env.VUE_APP_BASE_API,
            loading:false,
            dialogVisible:false,
            dialogImageUrl:'',
            taskName:'',
            title:'',
            taskId:'',
            definitionName:'',
            btnLoading:true,
            form:{
                title:'',
                contact_person:'',
                contact_information:'',
                network_environment:'',
                ipLocation:'',
                fault_phenomenon:'',
                files:''
            },
            // 网络环境下拉数据
            networkList:[
                {
                    id:'政务外网',
                    name:'政务外网'
                },
                {
                    id:'互联网',
                    name:'互联网'
                }
            ],
            fileList:[],
            rules:{

            }
        }
    },
    created(){
        this.Getdata()
    },
    computed: {
        visitedViews() {
            return this.$store.state.tagsView.visitedViews
        },
        routerUrl(){
            return this.$route.path
        }
    },
    watch: {
        visitedViews(value) {
            if(value){
                if(this.$options.name == 'NetworkFailuresDonedetails'){
                    return
                }
                this.$destroy(this.$options.name)
            }
        },
        routerUrl(value){
            if(value == '/faultdeclara/NetworkFailures/Donedetails'){
                this.Getdata()
            }
        }
    },
    methods:{
      download(item) {
          let downloadFile =
              this.base_url +
              "/system/downloadFile?fileName=" +
              item.fileName +
              "&filePath=" +
              item.filePath;
          window.location.href = downloadFile;
      },
      previewFile(item) {
         this.dialogImageUrl = this.base_url + item.filePath;
         this.dialogVisible = true;
      },
        Getdata(){
            var list = JSON.parse(sessionStorage.getItem('NetworkFailuresDonedetails'));
            this.btnLoading = false
            Getformdata(list.processInstanceId).then(res=>{
                this.form = res.data
                this.fileList = res.data.files
            })
        },
        handleChange(res, fileList){
            this.fileList = fileList;
        },
        DeleteFile(data, index) {
            DelectUploadFile(id).then(res => {
                if (res.code == 200) {
                    this.form.files = this.form.files.filter(item => {
                    if (item.id == id) {

                    } else {
                        return item
                    }
                    })
                    this.fileList = this.fileList.filter(item => {
                    if (item.id == id) {

                    } else {
                        return item
                    }
                    })
                    this.$message({
                    message: '删除成功',
                    type: 'success'
                    });
                }
            })
        },
        changeExamineShow(num,leble){
            this.$prompt('请输入审批意见', num == 1 ? '通过': '不通过', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
            inputValue:num == 1 ? '通过': '不通过',
            }).then((resp) => {
                taskComplete({
                    taskId: this.taskId,
                    actionName: num == 1 ? '通过': '不通过',
                    action: num == 1 ? 'COMPLETE': 'BACK',
                    formData: this.form,
                    formDefKey:this.form.formDefKey,
                    files:this.fileList,
                    comment:resp.value
                }).then(res=>{
                    if(res.code == 200){
                        this.$message({
                            type: 'success',
                            message: res.msg
                        });
                        this.$store.state.tagsView.visitedViews.splice(this.$store.state.tagsView.visitedViews.findIndex(item => item.path === this.$route.path), 1)
                        this.$destroy(this.$options.name)
                        this.$router.push('/todoItem/todo')
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消操作'
                });
            });
        }
    }
}
</script>

<style scoped lang="scss">
.dialog {
    .title {
        text-align: left;
        margin-bottom: 20px;
        font-size: 18px;
        font-weight: bold;
        padding-left: 4px;
        border-left: 4px solid #38b3aa;
    }
    .Subhead {
        text-align: left;
        margin-bottom: 20px;
        font-size: 14px;
        font-weight: bold;
        padding-left: 4px;
        border-left: 2px solid #38b3aa;
    }
    .tabletitle{
        width: 100%;
        text-align: center;
        font-weight: bold;
        border: 1px solid rgb(248,248,249);
        height: 40px;
        line-height: 40px;
        border-bottom: none;
    }
}
</style>
